<?php

header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=suscriptores-".date("d-m-Y", time()).".csv");

//including the library that allows to use the wpdb object with external files
require_once('../../../../../wp-load.php');

//retrieve the email address from the database
global $wpdb;

$suscriptores = $wpdb->get_results("SELECT email FROM suscriptores ORDER BY id_suscriptor ASC");

if (count($suscriptores) > 0) {
    $nl = "\n";
    $data = "";
    //$data='"email"'.$nl;
    foreach ($suscriptores as $suscriptor) {
        $data = $data . '"' . $suscriptor->email . '"' . $nl;
    } //
}

echo $data;
?>
